package day7.sp;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class MarketTest {
    public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            Market market =Market.readFromFile();
            if(market==null){
                market=new Market();
                System.out.println("请输入这个新商场的地址和名字：");
                market.setAddress(in.next());
                market.setName(in.next());
            }
            AutoSaveThread a=new AutoSaveThread(market);
            a.start();
            //
            Map<String,Integer> map =new HashMap<>();
            map.put("iphone6",6);
            map.put("血压计",10);
            map.put("抽纸",20);
            for (Map.Entry entry:map.entrySet()){
                System.out.println(entry.getKey()+"=="+entry.getValue());
            }

            while (true) {
                System.out.println("1：开卡     2：显示会员信息    3：积分添加     4：兑换奖品   5:查询剩余积分  6：修改密码   9:退出");
                int m = in.nextInt();
                if (m == 1) {
                    System.out.println("卡号：");
                    String cardNumber = in.next();
                    System.out.println("姓名：");
                    String name = in.next();
                    System.out.println("手机：");
                    String phone = in.next();
                    System.out.println("密码：");
                    String password = in.next();
                    market.addk(cardNumber,name,phone,password);
                } else if (m == 2) {
                    market.inof();
                } else if (m == 3) {
                    System.out.println("请输入查询的卡号：");
                    String cardNumber = in.next();
                    System.out.println("请输入需要加入的积分：");
                    int integral = in.nextInt();
                    market.addIntegral(cardNumber, integral);
                } else if (m == 4) {
                    System.out.println("请输入查询的卡号：");
                    String cardNumber = in.next();
                    System.out.println("请输入查询的密码：");
                    String password = in.next();
                    market.cashPrize(map,cardNumber,password);
                } else if (m == 5) {
                    System.out.println("请输入查询的卡号：");
                    String cardNumber = in.next();
                    market.queryIntegral(cardNumber);
                } else if (m == 6) {
                    System.out.println("请输入查询的卡号：");
                    String cardNumber = in.next();
                    System.out.println("请输入查询的密码：");
                    String password = in.next();
                    market.changePassword(cardNumber, password);
                } else if (m == 9) {
                    Market.storeObj(market);
                    //System.exit(0)
                    break;
                }

            }
    }
}
